import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';
import 'package:kq_flutter_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_widgets/theme/kq_theme_manager.dart';
import 'package:kq_flutter_widgets/widgets/bottomSheet/kq_botton_sheet_manger.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_head_button.dart';
import 'package:kq_flutter_widgets/widgets/pullRefresh/kq_refresh_footer.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

import '../../../resources/Images.dart';
import '../../../router/route_map.dart';
import 'controller.dart';

/// 首页
class HomePage extends StatelessWidget {
  const HomePage({super.key});

  /// 菜单布局
  Widget gridMenuItem(String menuName, GestureTapCallback? onTap) {
    return KqInkWell(
      onTap: onTap,
      borderWidth: 1,
      borderColor: KqThemeManager.getCommonConfig().mainColor ?? KqThemeColors.bgBlue,
      radius: 8.r,
      backgroundColor: KqThemeColors.bgWhite,
      child: Container(
        padding: EdgeInsets.all(10.r),
        child: Text(
          menuName,
          style: TextStyle(
            fontWeight: FontWeight.bold,
            color: Colors.black,
            fontSize: 20.sp,
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(HomeController());
    final state = Get.find<HomeController>().state;

    return GetBuilder<HomeController>(
        init: controller,
        builder: (controller) {
          return Scaffold(
            key: state.scaffoldKey,
            appBar: KqHeadBar(
              headTitle: '组件库演示',
              backIcon: Image.asset(
                Images.demoScanbtn,
                width: 20.r,
                height: 20.r,
                fit: BoxFit.fill,
              ),
              actions: KqHeadButton(
                widget: Icon(Icons.color_lens, size: 24.r,),
                menuData: [
                  KqPopMenuItemData(title: '黄色主题', hasPermission: true),
                  KqPopMenuItemData(title: '红色主题', hasPermission: true),
                  KqPopMenuItemData(title: '蓝色主题', hasPermission: true),
                  KqPopMenuItemData(title: '黑色主题', hasPermission: true),
                ],
                onSelected: (position, entity) {
                  controller.changeTheme(position);
                },
              ),
            ),
            body: GetBuilder<HomeController>(
              builder: (controller) => EasyRefresh(
                controller: controller.refreshController,
                onRefresh: controller.onRefresh,
                onLoad: controller.onLoad,
                footer: const KqRefreshFooter(),
                // child: ListView.builder(
                //   padding: EdgeInsets.zero,
                //   itemCount: 40, itemBuilder: (context, index) {
                //   return Container(height: 50.r, color: index % 2 == 0 ? Colors.red : Colors.blue,);
                // },)
                child: GridView.count(
                  crossAxisCount: 2,
                  scrollDirection: Axis.vertical,
                  //宽高比
                  childAspectRatio: 3 / 1.2,
                  padding: EdgeInsets.all(12.r),
                  mainAxisSpacing: 12.r,
                  crossAxisSpacing: 12.r,
                  children: [
                    gridMenuItem('按钮组件', () {
                      RouteMap.pushButtonDemo();
                    }),
                    gridMenuItem('表单组件', () {
                      RouteMap.pushFormDemo();
                    }),
                    gridMenuItem('对话框组件', () {
                      RouteMap.pushDialogDemo();
                    }),
                    gridMenuItem('折叠组件', () {
                      RouteMap.pushExpandListDemo();
                    }),
                    gridMenuItem('网格列表组件', () {
                      RouteMap.pushWrapFlowDemo();
                    }),
                    gridMenuItem('下拉菜单', () {
                      RouteMap.pushPullDownDemo();
                    }),
                    gridMenuItem('下拉菜单2', () {
                      RouteMap.pushPullDownSimpleDemo();
                    }),
                    gridMenuItem('下拉菜单3', () {
                      RouteMap.pushDropDownMenuDemo();
                    }),
                    gridMenuItem('空布局', () {
                      RouteMap.pushEmptyDemo();
                    }),
                    gridMenuItem('表格', () {
                      RouteMap.pushTableDemo();
                    }),
                    gridMenuItem('手写签名', () {
                      RouteMap.pushSignaturePadDemo();
                    }),
                    gridMenuItem('图表', () {
                      RouteMap.pushChartPage();
                    }),
                    gridMenuItem('面包屑', () {
                      RouteMap.pushBreadCrumbsDemo();
                    }),
                    gridMenuItem('轮播图', () {
                      RouteMap.pushSwiperDemo();
                    }),
                    gridMenuItem('文件选择与文件预览', () {
                      RouteMap.goFilePickerPage();
                    }),
                    gridMenuItem('更多自定义控件演示', () {
                      RouteMap.pushCustomViewsPage();
                    }),
                    gridMenuItem('更多自定义控件演示2', () {
                      RouteMap.pushCustomExpandPage();
                    }),
                    gridMenuItem('底部弹窗', () {
                      KqBottomSheetManager.showBottomSheet(
                        '底部弹窗',
                        Container(
                          height: 700.r,
                        ),
                      );
                    }),
                    gridMenuItem('可选择的gridview', () {
                      RouteMap.pushKqSelectableGridView();
                    }),
                    gridMenuItem('抽屉', () {
                      RouteMap.pushKqDrawer();
                    }),
                    gridMenuItem('溢出组件', () {
                      RouteMap.pushKqOverFlowBox();
                    }),
                    gridMenuItem('时间轴', () {
                      RouteMap.pushKqStepLineDemo();
                    }),
                    gridMenuItem('卡片', () {
                      RouteMap.pushKqCardDemo();
                    }),
                    gridMenuItem('悬浮控件', () {
                      RouteMap.pushFloatingViewDemoPage();
                    }),
                    gridMenuItem('动画', () {
                      RouteMap.pushAnimateDemo();
                    }),
                    gridMenuItem('TabBar + TabBarView', () {
                      RouteMap.pushTabBarAndViewDemo();
                    }),
                    gridMenuItem('视频播放', () {
                      RouteMap.pushVideoPlayDemo();
                    }),
                    gridMenuItem('特殊定制控件', () {
                      RouteMap.pushSpecialOrderDemo();
                    }),
                    gridMenuItem('更多文本', () {
                      RouteMap.pushEllipsisText();
                    })
                  ],
                ),
              ),
            ),
          );
        });
  }
}
